IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MFBreakFileNameWithPath]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
     DROP FUNCTION [dbo].[MFBreakFileNameWithPath]
END
GO

CREATE FUNCTION [dbo].[MFBreakFileNameWithPath](@FileNameWithPath [nvarchar](4000))
RETURNS  TABLE (
	[FilePath] [nvarchar](128) NULL,
	[FileName] [nvarchar](128) NULL
) WITH EXECUTE AS CALLER
AS 
EXTERNAL NAME [FileManipulationSQLCLRExternal].[FileManipulationSQLCLRExternal.UserDefinedFunctions].[MFBreakFileNameWithPath]
GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MFGetDirectoryList]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
     DROP FUNCTION [dbo].[MFGetDirectoryList]
END
GO

CREATE FUNCTION [dbo].[MFGetDirectoryList](@Directory [nvarchar](4000))
RETURNS  TABLE (
	[FilePath] [nvarchar](128) NULL,
	[FileName] [nvarchar](128) NULL,
	[FileNameWithPath] [nvarchar](255) NULL
) WITH EXECUTE AS CALLER
AS 
EXTERNAL NAME [FileManipulationSQLCLRExternal].[FileManipulationSQLCLRExternal.UserDefinedFunctions].[MFGetDirectoryList]
GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MFGetFileSpecs]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
     DROP FUNCTION [dbo].[MFGetFileSpecs]
END
GO

CREATE FUNCTION [dbo].[MFGetFileSpecs](@FilePath [nvarchar](4000), @FileName [nvarchar](4000))
RETURNS  TABLE (
	[FileSize] [int] NULL,
	[FileDt] [datetime] NULL,
	[FileExistFlag] [tinyint] NULL
) WITH EXECUTE AS CALLER
AS 
EXTERNAL NAME [FileManipulationSQLCLRExternal].[FileManipulationSQLCLRExternal.UserDefinedFunctions].[MFGetFileSpecs]
GO
